{include file="common/head"}
<head>
    <title>{$type_name}管理</title>

    <style>
        a{text-decoration:none;}
        input{display:initial!important;}
    </style>
</head>
<body >
<div class="container-fluid">
    <form action="/index.php/customer/index" method="post">
        <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
            <div class="col-4" style="text-align: left;line-height: 50px;font-size: 2rem;" >
                <input type="hidden" name="show_grid" id="show_grid" value="{$show_grid}" />
                {$type_name}管理
                <button type="button" class="btn btn-sm btn-primary" id="show_grid_change">
                    {if $show_grid!=1}
                        <span class="bi-grid"></span>
                    {else}
                        <span class="bi-table"></span>
                    {/if}
                </button>

            </div>
            <div class="col-8">

            <label for="type" >客户类型：</label>
            <select name="type" class="form-control" style="width:140px;display:initial;">
                <option value="">客户类型</option>
                {foreach $types as $k=>$v}
                    <option value="{$k}" >{$v}</option>
                {/foreach}
            </select>

            <label for="name" >姓名：</label>
            <input class="form-control" type="text"  id="name" name="name" value="{$name}" placeholder="姓名" />
            <label for="mobile" >手机：</label>
            <input class="form-control" type="text"  id="mobile" name="mobile" value="{$mobile}" placeholder="手机号码" />
            <button type="button" class="btn btn-warning query" style="vertical-align: middle;" >
                <span class="bi-search" ></span>
            </button>
            </div>
        </div>
    </form>
    {if $show_grid==1}
    <div id="cust_grid" style="display: flex;flex-wrap: wrap;">
        {foreach $list['data'] as $k=>$kv}
            <div class="cust_card row" style="width:300px;margin: 10px;box-shadow: 1px 1px 2px #444;padding:4px;">
                <div class="col-5">
                    <image class="goods_image" src="{$kv['image']}" style="width:100%;" />
                    <div style="color:blue;text-align:center;">{$kv['name']} </div>
                </div>
                <div class="col-7">
                    <div>手机：{$kv['mobile']} </div>
                    <div>状态：{$kv['status_name']} </div>
                    <div class="text-center">
                        <a href="/index.php/customer/edit/id/{$kv['id']}" title="编辑">
                            <button type="button" class="btn btn-sm btn-info" >
                                <span class="bi-pencil">编辑</span>
                            </button> 
                        </a>
                    <button type="buttun" onClick="resetPwd({$kv['id']})" class="btn btn-sm btn-danger" title="重置密码"> 
                        <span class="bi-key"></span>
                    </button>                        
                    </div>
                </div>
            </div>
        {/foreach}
    </div>

    {else}
    <table class="table table-sm table-hover table-striped table-bordered ">
        <thead class="table-info">
            <th>序号</th>
            <!-- <th>{$type_name}编号</th> -->
            <th>客户名称</th>
            <th>客户电话</th>
            <th>联系人</th>
            <th>联系人手机</th>
            <th>微信</th>
            <th>客户地址</th>
            <th>状态</th>
            <th>
                <a href="/index.php/customer/customer_add" alt="新学员登记">
                <button type="button" class="btn btn-sm btn-primary">
                    <span class="bi-plus-lg" style="color:white;"></span>
                </button>
                </a>
            </th>
        </thead>
        <tbody>
            {foreach $list['data'] as $k=>$kv}
            <tr>
                <td>{$k+1}</td>
                <td class="long_field">{$kv['name']}<br />{$kv['name2']}</td>
                <td>{$kv['tel']}</td>
                <td>{$kv['contact']}</td>
                <td>{$kv['mobile']}</td>
                <td>{$kv['wx']}</td>
                <td>{$kv['address']}</td>
                <td {if $kv['status']==2} style='color:red;font-weight: bold;' {/if}>{$kv['status_name']}</td> 
                <td>
                    <a href="/index.php/customer/edit/id/{$kv['id']}" title="编辑">
                        <button style="button" class="btn btn-sm btn-secondary"><span class="bi-pencil"></span></button>
                    </a>

                    {if $kv['status']==2}
                    <button type="buttun" onClick="remove_item({$kv['id']})" class="btn btn-sm btn-danger" title="删除"> 
                        <span class="bi-trash"></span>
                    </button>
                    {/if}

              
                </td>
            </tr>
            {/foreach}
            
        </tbody>
    </table>
    {/if}

    {include file="common/pagination"}
</div>
    <div id="mask"></div>
</body>



<script type="text/javascript">

  function remove_item(id){
    if(!id) return false;
    layer.confirm('是否确定删除客户资料?', {btn: ['是的','不了']}, function(){
        $.post('/order/order_cancel',{table:'customer',id:id,'name':'删除客户'},
        function(res){
            //layer.msg(res.msg);
            location.reload();
        })
    }, function(){
        layer.msg("好的!");
        return 0;
    });    
  }

  $(document).ready(function(){
    $(".query").on('click',function(){
        var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2

        $("form").submit();
        layer.close(index);
    }) 


    $("#mask").on('click',function(){
        $("#st_box").hide();
        $(this).hide();
    })

    $("#show_grid_change").on('click',function(){
        val =$("#show_grid").val();
        console.log(val);
        $("#show_grid").val(val*1>0?0:1);
        $('form').submit();
    })

    $(".goods_image").on('click',function(){
        var img = $(this).attr('src');
        if(!img.trim()) return;

        layer.open({
          type: 1,
          title:'',
          closeBtn: 0, //不显示关闭按钮
         // anim: 1,
          time: 5*1000,
          shadeClose: true, //开启遮罩关闭              
          skin: 'layui-layer-rim', 
          content: "<img src='"+img+"' style='height:100%'>"
        });
    })    



  })

</script>


</body>
</html>
